package lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.function.Consumer;

/**
 * @author LIBOFEI
 * @ClassName LambdaTest6
 * @description
 * @date 2020/10/9 15:02
 * @Version 1.0
 **/
public class LambdaTest6 {

    public static void main(String[] args) {

        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7);

        list.forEach(System.out::println);

        list.forEach(element -> {
                    if(element % 2 == 0){
                        System.out.println(element);
                    }
                }
        );



        ArrayList<Item> arrayList = new ArrayList<>();
        arrayList.add(new Item(4,"不达意",4));
        arrayList.add(new Item(1,"不达意",1));
        arrayList.add(new Item(5,"不达意",5));
        arrayList.add(new Item(6,"不达意",6));
        arrayList.add(new Item(2,"不达意",2));
        arrayList.add(new Item(3,"不达意",3));

        arrayList.forEach(System.out::println);
        arrayList.removeIf(ele -> ele.getId()==6);
        arrayList.forEach(System.out::println);

        /***1
        arrayList.sort(new Comparator<Item>() {
            @Override
            public int compare(Item o1, Item o2) {
                return o1.getId() - o2.getId();
            }
        });
        ***/
        /***2
        arrayList.sort(((o1, o2) -> o1.getId() - o2.getId()));
        ***/
        //3
        arrayList.sort((Comparator.comparingInt(Item::getId)));

        arrayList.forEach(System.out::println);
    }

}
